<template>
  <div class="app-container">

    <div class="filter-container">
      <el-date-picker
        v-model="listQuery.checktime"
        type="daterange"
        range-separator="至"
        class="filter-item"
        style="width:300px"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd"
      >
      </el-date-picker>

      <el-button-group class="filter-item">
        <el-button
          size="small"
          type="primary"
          icon="el-icon-search"
          @click="search"
        >
          搜索
        </el-button>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-refresh"
          @click="refresh"
        >
          重置
        </el-button>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-paperclip"
          @click="explortExcel"
        >
          导出
        </el-button>

      </el-button-group>

    </div>
    <div style="display: flex;width: 100%">
      <div>
        <el-table
          v-loading="listLoading"
          :data="rankData.data"
          id="table"
          element-loading-text="Loading"
          fit
          height="100%"
          border
          row-class-name="rowpadding"
          header-row-class-name="headerClass"
          class="table-container"
          highlight-current-row
        >

          <el-table-column
            width="150"
            label="领域"
            align="center"
          >
            <template slot-scope="scope">
              <div class="fontSize">{{ scope.row.type }}</div>
            </template>
          </el-table-column>

          <el-table-column
            label="数量"
            width="135"
            align="center"
          >
            <template slot-scope="scope">
              <div class="fontSize">{{ scope.row.num }}</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div style="width:50%;max-width:350px;margin-left:30px;">
        <el-col>
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>性质统计</span>
            </div>
            <div class="block">
              <div style="padding-top:35px;" class="progress-item" v-for="(item,idx) in rankData.data">
                <span>{{ item.type }} <span style="color:#ed883f;font-weight: bold">{{ item.num }}</span></span>
                <el-progress :percentage="parseFloat(((item.num/rankData.count)*100).toFixed(2))"/>
              </div>
            </div>
          </el-card>
        </el-col>
      </div>
    </div>
  </div>
</template>
<style>
.el-card__header{
  padding:15px 20px;
}
.el-progress{
  margin-top:5px;
  display: flex;
}
.progress-item{
  padding-top:0 !important;
  padding-bottom: 30px;
}
</style>
<script>
import exportExecl from '@/utils/excel'
import { getRankData } from '@/api/rank'

let id = 0
export default {
  data() {
    return {
      total: 0,
      list: [],
      drawer: true,
      rankData: [],
      countTypeData: [],
      listLoading: false,
      listQuery: {
        checktime: ['2023-11-1', '2023-11-15'],             //时间范围
        chart: 3
      },
      baseData: [],
      dialogVisible: false,
      dialogType: 'create',
      loading: false
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    search() {
      this.fetchData()
    },
    refresh() {
      this.listQuery = {
        chart: 3,
        checktime: '',
      }
    },
    explortExcel() {
      let fileName = (this.listQuery.checktime[0]) + '至' + (this.listQuery.checktime[1]) + '的领域数据'
      exportExecl('table', fileName + '.xlsx')
    },
    fetchData() {
      // if (!this.listQuery.checktime || !this.listQuery.chart) {
      //   this.$message({
      //     message: '请完善筛选条件',
      //     type: 'error'
      //   })
      //   return false
      // }
      // this.listLoading = true
      getRankData(this.listQuery).then(response => {
        this.listLoading = false
        this.rankData = response.data
      })
    }
  }
}
</script>
